package pokerSaloon.vue;
import pokerSaloon.controller.AccueilController;

/*
 * fenAccueil.java
 *
 * Created on 20 févr. 2010, 19:26:44
 */


/**
 *
 * @author animateur
 */
public class fenAccueil extends javax.swing.JFrame implements View {

    /**
	 * 
	 */
	private static final long serialVersionUID = -7352235706302160860L;
	
	private AccueilController controller;
	
	/** Creates new form fenAccueil */
    public fenAccueil(AccueilController controller) {
    	this.controller = controller;
        initComponents();
    }


    private void initComponents() {

        labelTitre = new javax.swing.JLabel();
        panConnexion = new javax.swing.JPanel();
        btnConnecter = new javax.swing.JButton();
        labelPseudo = new javax.swing.JLabel();
        labelIPServeur = new javax.swing.JLabel();
        saisiePseudo = new javax.swing.JFormattedTextField();
        saisieIP = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        menuPrincipal = new javax.swing.JMenuBar();
        menuPokerSaloon = new javax.swing.JMenu();
        menuItemConnecter = new javax.swing.JMenuItem();
        menuItemQuitter = new javax.swing.JMenuItem();
        menuAide = new javax.swing.JMenu();
        menuItemManuel = new javax.swing.JMenuItem();
        MenuItemAPropos = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Poker Saloon - Accueil");
        setResizable(false);

        labelTitre.setFont(new java.awt.Font("Purisa", 1, 48));
        labelTitre.setForeground(java.awt.Color.red);
        labelTitre.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelTitre.setText("Poker Saloon");

        panConnexion.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Connexion", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Sans", 0, 13))); // NOI18N

        btnConnecter.setText("Se connecter");
        btnConnecter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConnecterActionPerformed(evt);
            }
        });

        labelPseudo.setText("Pseudo :");

        labelIPServeur.setText("IP serveur :");

        try {
            saisiePseudo.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("******************")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }


        jLabel1.setText(" (de 3 \u00E0 15 caract\u00E8res)");

        javax.swing.GroupLayout gl_panConnexion = new javax.swing.GroupLayout(panConnexion);
        panConnexion.setLayout(gl_panConnexion);
        gl_panConnexion.setHorizontalGroup(
            gl_panConnexion.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_panConnexion.createSequentialGroup()
                .addGroup(gl_panConnexion.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(gl_panConnexion.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(gl_panConnexion.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(labelIPServeur)
                            .addComponent(labelPseudo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(gl_panConnexion.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(saisiePseudo, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
                            .addComponent(saisieIP, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
                            .addComponent(jLabel1)))
                    .addGroup(gl_panConnexion.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(btnConnecter)))
                .addContainerGap())
        );
        gl_panConnexion.setVerticalGroup(
            gl_panConnexion.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_panConnexion.createSequentialGroup()
                .addContainerGap()
                .addGroup(gl_panConnexion.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelIPServeur, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(saisieIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gl_panConnexion.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelPseudo, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(saisiePseudo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnConnecter)
                .addContainerGap())
        );

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/logo_poker.gif"))); // NOI18N

        menuPokerSaloon.setText("Poker Saloon");

        menuItemConnecter.setText("Se connecter");
        menuItemConnecter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemConnecterActionPerformed(evt);
            }
        });
        menuPokerSaloon.add(menuItemConnecter);

        menuItemQuitter.setText("Quitter");
        menuItemQuitter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemQuitterActionPerformed(evt);
            }
        });
        menuPokerSaloon.add(menuItemQuitter);

        menuPrincipal.add(menuPokerSaloon);

        menuAide.setText("Aide");

        menuItemManuel.setText("Manuel d'utilisation");
        menuAide.add(menuItemManuel);

        MenuItemAPropos.setText("A propos");
        MenuItemAPropos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuItemAProposActionPerformed(evt);
            }
        });
        menuAide.add(MenuItemAPropos);

        menuPrincipal.add(menuAide);

        setJMenuBar(menuPrincipal);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jLabel2)
                        .addGap(76, 76, 76)
                        .addComponent(panConnexion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(labelTitre, javax.swing.GroupLayout.DEFAULT_SIZE, 563, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelTitre, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jLabel2)
                        .addContainerGap(22, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(panConnexion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(56, 56, 56))))
        );

        pack();
    }

    private void btnConnecterActionPerformed(java.awt.event.ActionEvent evt) {
    	String pseudo = saisiePseudo.getText().trim().replaceAll(" ","_");
    	String adresseIP  = saisieIP.getText().trim();
    	controller.connexion(adresseIP, pseudo);
    }

    private void menuItemQuitterActionPerformed(java.awt.event.ActionEvent evt) {
        if(javax.swing.JOptionPane.showConfirmDialog(this,
                "Voulez-vous vraiment quitter ?", "Confirmation",
                javax.swing.JOptionPane.YES_NO_OPTION,-1) == 0) {
            this.dispose();
        }
    }

    private void menuItemConnecterActionPerformed(java.awt.event.ActionEvent evt) {
        btnConnecter.doClick();
    }

    private void MenuItemAProposActionPerformed(java.awt.event.ActionEvent evt) {
        OutilsInterface.aPropos(this);

    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    /**
	 * @uml.property  name="menuItemAPropos"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenuItem MenuItemAPropos;
    /**
	 * @uml.property  name="btnConnecter"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JButton btnConnecter;
    /**
	 * @uml.property  name="jLabel1"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JLabel jLabel1;
    /**
	 * @uml.property  name="jLabel2"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JLabel jLabel2;
    /**
	 * @uml.property  name="labelIPServeur"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JLabel labelIPServeur;
    /**
	 * @uml.property  name="labelPseudo"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JLabel labelPseudo;
    /**
	 * @uml.property  name="labelTitre"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JLabel labelTitre;
    /**
	 * @uml.property  name="menuAide"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenu menuAide;
    /**
	 * @uml.property  name="menuItemConnecter"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenuItem menuItemConnecter;
    /**
	 * @uml.property  name="menuItemManuel"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenuItem menuItemManuel;
    /**
	 * @uml.property  name="menuItemQuitter"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenuItem menuItemQuitter;
    /**
	 * @uml.property  name="menuPokerSaloon"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenu menuPokerSaloon;
    /**
	 * @uml.property  name="menuPrincipal"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JMenuBar menuPrincipal;
    /**
	 * @uml.property  name="panConnexion"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JPanel panConnexion;
    /**
	 * @uml.property  name="saisieIP"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JTextField saisieIP;
    /**
	 * @uml.property  name="saisiePseudo"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private javax.swing.JFormattedTextField saisiePseudo;
    // End of variables declaration//GEN-END:variables

	@Override
	public void displayView() {
		this.setVisible(true);	
	}


	@Override
	public void removeView() {
		this.dispose();
	}


	@Override
	public void afficheMsgDialog(String message, String titre) {
		 javax.swing.JOptionPane.showMessageDialog(this, message,titre,2);
	}

    
}
